<?php
function admin($str='0',$ty='0'){
	global $pre,$db,$webdb,$WEBURL,$timestamp;
	if (empty($_SESSION[$webdb['session_admin']])){
		$_SESSION[$webdb['session_admin'].'_admin_url']=$WEBURL;
		refreshto('index.php','对不起你没有登陆或登陆超时!');
	}
	/*if($timestamp-$_SESSION[$webdb['session_admin'].'_time']>3000){
		unset($_SESSION[$webdb['session_admin']]);
		unset($_SESSION[$webdb['session_admin'].'_time']);
		$_SESSION[$webdb['session_admin'].'_admin_url']=$WEBURL;
		refreshto('goods.php','对不起你没有登陆或登陆超时!');
	}*/
	$adminssion=$db->get_one("SELECT * FROM {$pre}admin where u_name='".$_SESSION[$webdb['session_admin']]."' and u_or='1'");
	if(!$adminssion){//当没有该用户的时候unset($_SESSION[$webdb['session_admin']]);
		//$SESSION[$webdb['session_admin'].'_admin_url']=$WEBURL;
//        $_SESSION[$webdb['session_admin']]=  '';
		refreshto('index.php','对不起你没有登陆或登陆超时!');

	}
	if($str<>'0'){
		if(jiaoji($str)==0){
			if($ty=='1'){
				return '0';
			}else{	
				refreshto('right.php','对不起你没有该功能的管理权限!',5);
			}
		}else{
			if($ty=='1'){
				return '1';
			}
		}
	}
	$_SESSION[$webdb['session_admin'].'_time']=$timestamp;
}

//

if(!empty($_SESSION[$webdb['session_admin']])){
	$adminarr=$db->get_one("SELECT a.*,b.title FROM {$pre}admin a ,{$pre}admin_group b  where a.u_group=b.id  and a.u_name='".$_SESSION[$webdb['session_admin']]."'");
	//$admin_area=$adminssion[u_area];
	$admin_id=$adminarr['u_id'];
}

//

//后台用户权限判断的
function jiaoji($str,$admin=''){
	global $db,$pre,$webdb;
	if(!$admin){
		$adminname=$_SESSION[$webdb['session_admin']];
	}else{
		$adminname=$admin;
	}
	$webben=$db->get_one("SELECT * FROM {$pre}admin where u_name='".$adminname."'");
	if($webben){
		$a = explode(",",$webben['u_ssion']);
		foreach ($a as $v) {	
			if ($v==$str){
				$cont='1';
				break; 
			}else{
				$cont="0";
			}
		}
	}else{
		$cont="0";
	}
	return $cont;
}
?>